package com.flower.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.flower.domain.entity.productSpecs.AttributeKey;
import com.flower.domain.entity.productSpecs.AttributeValue;
import com.flower.mapper.AttributeKeyMapper;
import com.flower.service.AttributeKeyService;
import com.flower.service.AttributeValueService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * (AttributeKey)表服务实现类
 *
 * @author lixinghe
 * @since 2023-05-08 22:02:49
 */
@Service("attributeKeyService")
public class AttributeKeyServiceImpl extends ServiceImpl<AttributeKeyMapper, AttributeKey> implements AttributeKeyService {

    @Resource
    private AttributeValueService attributeValueService;

    @Override
    public List<AttributeKey> cList(Long categoryId) {
        LambdaQueryWrapper<AttributeKey> wrapper = new LambdaQueryWrapper();
        wrapper.eq(AttributeKey::getCateId,categoryId);
        List<AttributeKey> attributeKeys = list(wrapper);
        attributeKeys.stream().map( item -> {
            LambdaQueryWrapper<AttributeValue> attributeValueLambdaQueryWrapper = new LambdaQueryWrapper<>();
            item.setAttributeValueList(attributeValueService.list(attributeValueLambdaQueryWrapper.eq(AttributeValue::getAttributeId, item.getId())));
            return item;
        }).collect(Collectors.toList());
        return attributeKeys;
    }

}
